import wx
import os

from PLGen import PLGen
from XMLHandler import VideoList,Settings

from ExportPanel import ExportPanel
from ListPanel import ListPanel
from AddPanel import AddPanel
from SettingsPanel import SettingsPanel

class MyApp(wx.App):

    def OnInit(self):
        self.settings = Settings().getSettings()
        self.plgen = PLGen(VideoList("default.xml"))
        self.frame = MainFrame(self.plgen, self.settings).Show()
        return True

class MainFrame(wx.Frame):
    def __init__(self, plgen, settings):
        wx.Frame.__init__(self, None, size=(600,400), title="Playlist Generator v0")

        panel = wx.Panel(self)
        self.notebook = wx.Notebook(panel)

        self.exportPage = ExportPanel(self.notebook, -1, plgen, settings)
        self.notebook.AddPage(self.exportPage, "Export")

        self.listPage = ListPanel(self.notebook, -1, plgen)
        self.notebook.AddPage(self.listPage, "Video List")

        self.addPage = AddPanel(self.notebook, -1, plgen, settings)
        self.notebook.AddPage(self.addPage, "Add Videos")

        self.settingsPage = SettingsPanel(self.notebook, -1, plgen, settings)
        self.notebook.AddPage(self.settingsPage, "Settings")

        wx.EVT_NOTEBOOK_PAGE_CHANGED(self, -1, self.OnPageChange)

        sizer = wx.BoxSizer()
        sizer.Add(self.notebook, 1, wx.EXPAND)
        panel.SetSizer(sizer)

    def OnPageChange(self, event):
        if event.GetSelection() == 1:
            self.listPage.updateList()

if __name__ == "__main__":
    app = MyApp(redirect = 0)
    app.MainLoop()